package cn.school.sys.dao;

import cn.school.sys.entity.SysUserRole;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 后台用户和角色关系表
 */
@Mapper
public interface SysUserRoleDao extends BaseMapper<SysUserRole> {
    /**
     * 根据用户id 批量添加用户角色关系
     * @param userId
     * @param roleIdList
     * @param
     */
    void insertUserAndUserRole(@Param("userId") Long userId, @Param("roleIdList") List<Long> roleIdList, @Param("tenantId") String tenantId);


    /**
     * 根据用户ID 获取角色数据权限标识
     * @param userId
     * @return
     */
    List<Integer> listDataScopesByUserId(Long userId);


    /**
     * 根据条件获取用户角色中间关系（并获取角色的名称）
     * */
    @Select("" +
            "select\n" +
            "   suro.*, syro.name as role_name\n" +
            "from \n" +
            "   t_sys_user_role suro left join t_sys_role syro on (\n" +
            "       suro.role_id = syro.id\n" +
            "   )\n" +
            "${ew.customSqlSegment}")
    List<SysUserRole> listByCase(@Param("ew") QueryWrapper<SysUserRole> queryWrapper);

    List<SysUserRole> findUserRoleList(@Param("userId") Long userid);
}
